package cn.myjerry.others.pro;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 使用Properties输出到文件
 * 资源配置文件
 * 
 * 1、.properties
 *    store(Writer writer, String comments)
 *    store(OutputStream out, String comments)
 *    load(Reader reader)
 *    load(InputStream inStream)
 * 2、.xml
 *    storeToXML(OutputStream os, String comment) => UTF-8 字符集
 *    storeToXML(OutputStream os, String comment, String encoding)
 *    loadFromXML(InputStream in)
 * @author Jerry
 *
 */

public class Demo02 {

	public static void main(String[] args) throws IOException {
		// 创建对象
		Properties pro = new Properties();
		// 存储
		pro.setProperty("driver", "oracle.jdbc.driver.OracleDriver");
		pro.setProperty("url", "jdbc:oracle:thin:@localhost:1521:orcl");
		pro.setProperty("user", "soctt");
		pro.setProperty("pwd", "tiger");
		// 存储到当前目录（相对路径）
		//pro.store(new FileOutputStream(new File("src/cn/myjerry/others/pro/db.properties")), "db配置");
		pro.storeToXML(new FileOutputStream(new File("src/cn/myjerry/others/pro/db.xml")), "db配置");
		
		//Properties pro1 = new Properties();
		
		//pro1.loadFromXML(new FileInputStream(new File("db.xml")));
		
		//System.out.println(pro1.getProperty("url"));
	}

}
